package com.example.a14110100409.yuejiandemo.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.a14110100409.yuejiandemo.R;
import com.example.a14110100409.yuejiandemo.activity.OrderInfoActivity;
import com.example.a14110100409.yuejiandemo.javabean.UserOrder;

import java.util.List;

import it.sephiroth.android.library.picasso.Picasso;

/**
 * Created by owner on 2017/10/17.
 */

public class NFinOrderAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>{
    private Context mContext;

    private List mDataList;//数据存储
    private LayoutInflater mLayoutInflater;//准备布局

    public NFinOrderAdapter(Context mContext, List mDataList) {
        this.mContext = mContext;
        this.mDataList = mDataList;
        mLayoutInflater = LayoutInflater.from(mContext);
    }



    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = mLayoutInflater.from(parent.getContext()).inflate(R.layout.cardview_allorder, parent, false);
        return new NFinOrderAdapter.ViewHolder(v);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {

        final UserOrder entity = (UserOrder) mDataList.get(position);

        if (null == entity)
            return;
        NFinOrderAdapter.ViewHolder viewHolder = (NFinOrderAdapter.ViewHolder) holder;
        viewHolder.order_id.setText("订单编号："+entity.getId());
        Log.v("PPPPPPPPPPPP",""+entity.getVstate());
        //viewHolder.order_state.setText("未参加");
        viewHolder.order_state.setText("未参加");
        if(entity.getName()==null){
            viewHolder.act_name.setText("此处数据为空");
        }else {
            viewHolder.act_name.setText(entity.getName());
        }
        if(entity.getPrice()==null){
            viewHolder.act_price.setText("￥300");
        }
        else {
            viewHolder.act_price.setText("￥"+entity.getPrice());
        }
        if (entity.getThumb()==null){
            viewHolder.order_pic.setImageResource(R.drawable.tx);
        }
        else {
            String address="http://172.24.10.175/workout/Uploads/"+entity.getThumb();
            Picasso.with(mContext).load(address).into(viewHolder.order_pic);
        }

        viewHolder.order_time.setText(entity.getUpdate_time());
        viewHolder.order_allprice.setText("订单总额："+entity.getPay()+"元");
        viewHolder.order_info.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(mContext,OrderInfoActivity.class);
                intent.putExtra("order_id",entity.getId());
                intent.putExtra("order_type",entity.getType());
                intent.putExtra("price",entity.getPrice());
                mContext.startActivity(intent);
            }
        });
    }

    public int getItemCount() {
        return mDataList.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder{
        ImageView order_pic;
        TextView order_id,order_state,act_name,act_price,order_time,order_allprice;
        LinearLayout order_info;

        public ViewHolder(View itemView) {
            super(itemView);
            order_pic = (ImageView) itemView.findViewById(R.id.order_pic);
            order_id = (TextView) itemView.findViewById(R.id.order_id);
            order_state = (TextView) itemView.findViewById(R.id.order_state);
            act_name = (TextView) itemView.findViewById(R.id.act_name);
            act_price = (TextView) itemView.findViewById(R.id.act_price);
            order_time = (TextView) itemView.findViewById(R.id.order_time);
            order_allprice = (TextView) itemView.findViewById(R.id.order_allprice);
            order_info = (LinearLayout) itemView.findViewById(R.id.order_info);
        }
    }
}
